package com.tyk.bookstore.back.product.mq;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

/**
 * @author tyk
 * @description 注册交换机和队列
 */

@Configuration
public class BookMqConfig {

    @Bean
    public CustomExchange bookReleaseExchange() {
        HashMap<String, Object> args = new HashMap<>() {{
            put("x-delayed-type", "direct");
        }};
        return new CustomExchange(
                BookMqConstant.BOOK_RELEASE_EXCHANGE,
                "x-delayed-message",
                true,
                false,
                args
        );
    }

    @Bean
    public Queue bookReleaseQUeue() {
        return new Queue(BookMqConstant.BOOK_RELEASE_QUEUE, true);
    }

    @Bean
    public Binding bookReleaseBinding() {
        return BindingBuilder
                .bind(bookReleaseQUeue())
                .to(bookReleaseExchange())
                .with(BookMqConstant.BOOK_RELEASE_ROUTING)
                .noargs();
    }


}
